#!/bin/sh
# -*- shell-script -*-
# Copyright (C) 2004-2012 GraphicsMagick Group
# Test image processing
# This script should be executed prior to Montage
. ./common.shi
. ${top_srcdir}/utilities/tests/common.sh

# Number of tests we plan to execute
test_plan_fn 59

OUTFILE=TileAddNoise_out.miff
rm -f ${OUTFILE}
test_command_fn 'AddNoise' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} +noise Laplacian -label AddNoise -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileAffine_out.miff
rm -f ${OUTFILE}
test_command_fn 'Affine' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -affine 1,0,0.785,1,0,0 -transform -label Affine -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileAnnotate_out.miff
ANNOTATE_CMD_FILE=annotate_cmds_out.txt
echo 'gravity North text 0,20 "Magick"' > ${ANNOTATE_CMD_FILE}
rm -f ${OUTFILE}
test_command_fn 'Annotate' -F TTF ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -fill gold -pointsize 14 \
	-font ${GENERIC_TTF} \
	-draw @${ANNOTATE_CMD_FILE} \
	-label Annotate -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileThresholdBlack_out.miff
rm -f ${OUTFILE}
test_command_fn 'Black-Threshold' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -black-threshold "20%" \
                   -label 'Black-Threshold' -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileBlur_out.miff
rm -f ${OUTFILE}
test_command_fn 'Blur' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -blur 0x1 -label Blur -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileBorder_out.miff
rm -f ${OUTFILE}
test_command_fn 'Border' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -bordercolor gold -border 6x6 -label Border -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileChannel_out.miff
rm -f ${OUTFILE}
test_command_fn 'Channel' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -colorspace cmyk -channel yellow -label Channel -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileCharcoal_out.miff
rm -f ${OUTFILE}
test_command_fn 'Charcoal' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -charcoal 0x1 -label Charcoal -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileComposite_out.miff
rm -f ${OUTFILE}
test_command_fn 'Composite' ${GM} composite ${COMPOSITE_FLAGS} ${SMILE_MIFF} -geometry +35+65 ${MODEL_MIFF} -label Composite -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileContrast_out.miff
rm -f ${OUTFILE}
test_command_fn 'Contrast' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -contrast -label Contrast ${OUTFILE}

OUTFILE=TileConvolve_out.miff
rm -f ${OUTFILE}
# 1,1,1,
# 1,4,1,
# 1,1,1
test_command_fn 'Convolve' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -convolve 1,1,1,1,4,1,1,1,1 -label Convolve -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileCrop_out.miff
rm -f ${OUTFILE}
test_command_fn 'Crop' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -crop '80x80+25+50' -label Crop -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileDespeckle_out.miff
rm -f ${OUTFILE}
test_command_fn 'Despeckle' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -despeckle -label Despeckle -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileDraw_out.miff
DRAWFILE=draw_circle_out.txt
rm -f ${OUTFILE}
echo 'circle 60,90 60,120' > ${DRAWFILE}
test_command_fn 'Draw' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -fill none -stroke gold \
         -draw @${DRAWFILE} -label Draw -compress ${MIFF_COMPRESS} ${OUTFILE}
rm -f ${DRAWFILE}

OUTFILE=TileEdge_out.miff
rm -f ${OUTFILE}
test_command_fn 'Edge' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -edge 0x1 -label Edge -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileEmboss_out.miff
rm -f ${OUTFILE}
test_command_fn 'Emboss' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -emboss 0x1 -label Emboss -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileEqualize_out.miff
rm -f ${OUTFILE}
test_command_fn 'Equalize' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -equalize -label Equalize -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileExplode_out.miff
rm -f ${OUTFILE}
test_command_fn 'Explode' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -implode -1 -label Explode -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileFlip_out.miff
rm -f ${OUTFILE}
test_command_fn 'Flip' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -flip -label Flip -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileFlop_out.miff
rm -f ${OUTFILE}
test_command_fn 'Flop' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -flop -label Flop -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileFrame_out.miff
rm -f ${OUTFILE}
test_command_fn 'Frame' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -frame 15x15+3+3 -label Frame -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileGamma_out.miff
rm -f ${OUTFILE}
test_command_fn 'Gamma' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -gamma 1.6 -label Gamma -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileGaussianBlur_out.miff
rm -f ${OUTFILE}
test_command_fn 'GaussianBlur' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -gaussian 0x1.5 -label GaussianBlur -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileGradient_out.miff
rm -f ${OUTFILE}
test_command_fn 'Gradient' ${GM} convert ${CONVERT_FLAGS} -size 130x194 gradient:'#20a0ff-#ffff00' -label Gradient -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileGrayscale_out.miff
rm -f ${OUTFILE}
test_command_fn 'Grayscale' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -colorspace gray -label Grayscale -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileImplode_out.miff
rm -f ${OUTFILE}
test_command_fn 'Implode' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -implode 0.5 -label Implode -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileLevel_out.miff
rm -f ${OUTFILE}
test_command_fn 'Level' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -level 10%,1.2,90% -label Level -compress ${MIFF_COMPRESS} ${OUTFILE}

rm -f mask_out.miff TileMask_out.miff
${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -threshold "30%" -compress ${MIFF_COMPRESS} mask_out.miff
test_command_fn 'Mask' ${GM} convert ${CONVERT_FLAGS} -mask mask_out.miff ${MODEL_MIFF} -negate -label Mask -compress ${MIFF_COMPRESS} TileMask_out.miff

OUTFILE=TileMedian_out.miff
rm -f ${OUTFILE}
test_command_fn 'MedianFilter' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -median 3 -label MedianFilter -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileModulate_out.miff
rm -f ${OUTFILE}
test_command_fn 'Modulate' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -modulate 110/110/110 -label Modulate -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileMonochrome_out.miff
rm -f ${OUTFILE}
test_command_fn 'Monochrome' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -colorspace gray -colors 2 \
                   +dither -label Monochrome -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileNegate_out.miff
rm -f ${OUTFILE}
test_command_fn 'Negate' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -negate -label Negate -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileNormalize_out.miff
rm -f ${OUTFILE}
test_command_fn 'Normalize' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -normalize -label Normalize -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileOilPaint_out.miff
rm -f ${OUTFILE}
test_command_fn 'Oilpaint' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -paint 0x1 -label Oilpaint -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileOrderedDither2_out.miff
rm -f ${OUTFILE}
test_command_fn 'Ordered2x2' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -equalize -ordered-dither intensity 2x2 -label Ordered2x2 -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileOrderedDither3_out.miff
rm -f ${OUTFILE}
test_command_fn 'Ordered3x3' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -equalize -ordered-dither intensity 3x3 -label Ordered3x3 -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileOrderedDither4_out.miff
rm -f ${OUTFILE}
test_command_fn 'Ordered4x4' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -equalize -ordered-dither intensity 4x4 -label Ordered4x4 -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TilePlasma_out.miff
rm -f ${OUTFILE}
test_command_fn 'Plasma' ${GM} convert ${CONVERT_FLAGS} -size 130x194 plasma:fractal -label Plasma -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileQuantize_out.miff
rm -f ${OUTFILE}
test_command_fn 'Quantize' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -colors 16 -label Quantize -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileRaise_out.miff
rm -f ${OUTFILE}
test_command_fn 'Raise' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -raise 10x10 -label Raise -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileRandomThreshold_out.miff
rm -f ${OUTFILE}
test_command_fn 'Random 10%' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -equalize -random-threshold intensity '10%' -label 'Random10%%' -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileRecolor_out.miff
MATRIXFILE=recolor_matrix_out.txt
echo '0.9 0 0, 0 0.9 0, 0 0 1.2' > ${MATRIXFILE}
rm -f ${OUTFILE}
test_command_fn 'Recolor' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -recolor @${MATRIXFILE} -label Recolor -compress ${MIFF_COMPRESS} ${OUTFILE}
rm -f ${MATRIXFILE}

OUTFILE=TileReduceNoise_out.miff
rm -f ${OUTFILE}
test_command_fn 'ReduceNoise' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -noise 0x1 -label ReduceNoise -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileResize_out.miff
rm -f ${OUTFILE}
test_command_fn 'Resize' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -resize 50% -label Resize -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileRoll_out.miff
rm -f ${OUTFILE}
test_command_fn 'Roll' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -roll +20+10 -label Roll -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileRotate_out.miff
rm -f ${OUTFILE}
test_command_fn 'Rotate 45' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -fill black -rotate 45 \
        -transparent black -label Rotate -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileScale_out.miff
rm -f ${OUTFILE}
test_command_fn 'Scale' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -scale 60% -label Scale -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileSegment_out.miff
rm -f ${OUTFILE}
test_command_fn 'Segment' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -segment 0.5x0.25 -label Segment -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileShade_out.miff
rm -f ${OUTFILE}
test_command_fn 'Shade' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -shade 30x30 -label Shade -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileSharpen_out.miff
rm -f ${OUTFILE}
test_command_fn 'Sharpen' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -sharpen 0x1 -label Sharpen -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileShave_out.miff
rm -f ${OUTFILE}
test_command_fn 'Shave' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -shave 10x10 -label Shave -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileShear_out.miff
rm -f ${OUTFILE}
test_command_fn 'Shear' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -fill black -shear 45x45 \
        -transparent black -label Shear -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileSolar_out.miff
rm -f ${OUTFILE}
test_command_fn 'Solarize' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -solarize 50% -label Solarize -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileSpread_out.miff
rm -f ${OUTFILE}
test_command_fn 'Spread' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -spread 3 -label Spread -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileSwirl_out.miff
rm -f ${OUTFILE}
test_command_fn 'Swirl' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -background '#000000FF' \
        -swirl 90 -label Swirl -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileThreshold_out.miff
rm -f ${OUTFILE}
test_command_fn 'Threshold' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -threshold "35%" \
                   -label Threshold -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileUnsharpMask_out.miff
rm -f ${OUTFILE}
test_command_fn 'UnsharpMask' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -unsharp 0x1+10+10 -label UnsharpMask -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileWave_out.miff
rm -f ${OUTFILE}
test_command_fn 'Wave' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -background '#000000FF' \
        -wave 25x150 -label Wave -compress ${MIFF_COMPRESS} ${OUTFILE}

OUTFILE=TileThresholdWhite_out.miff
rm -f ${OUTFILE}
test_command_fn 'White-Threshold' ${GM} convert ${CONVERT_FLAGS} ${MODEL_MIFF} -white-threshold "80%" \
                   -label 'White-Threshold' -compress ${MIFF_COMPRESS} ${OUTFILE}
:
